package com.swipemaster.common;

import android.content.Context;
import android.content.SharedPreferences;

/** Preferences (prefs) manager. */
public class Prefs
{
	public static final String MUSIC_KEY = "music_key";
	public static final String USER_ID_KEY = "user_id_key";
	public static final String FIRST_HELP_KEY = "first_help_key";
	public static final String SECOND_HELP_KEY = "second_help_key";
	public static final String LEVEL1_COINS_KEY = "level1_coins_key";
	public static final String LEVEL2_COINS_KEY = "level2_coins_key";
	public static final String CHALLENGE_HELP_KEY = "challenge_help_key";
	public static final String PREMIUM_KEY = "premium_key";
	public static final String GAMES_PLAYED_WHEN_STATS_SENT_KEY = "stats_games_played_key";
	public static final String COINS_KEY = "coins_key";

	private static final String FILENAME = "preferences";
	private SharedPreferences prefs = Global.app.getSharedPreferences(FILENAME, Context.MODE_PRIVATE);

	public boolean getBoolean(String key, boolean defValue)
	{
		return prefs.getBoolean(key, defValue);
	}

	public float getFloat(String key, float defValue)
	{
		return prefs.getFloat(key, defValue);
	}

	public int getInt(String key, int defValue)
	{
		return prefs.getInt(key, defValue);
	}

	public long getLong(String key, long defValue)
	{
		return prefs.getLong(key, defValue);
	}

	public String getString(String key, String defValue)
	{
		return prefs.getString(key, defValue);
	}

	public void putObject(String key, Object value)
	{
		final SharedPreferences.Editor editor = prefs.edit();
		if (value instanceof Boolean)
		{
			editor.putBoolean(key, (Boolean) value);
		}
		else if (value instanceof Float)
		{
			editor.putFloat(key, (Float) value);
		}
		else if (value instanceof Integer)
		{
			editor.putInt(key, (Integer) value);
		}
		else if (value instanceof Long)
		{
			editor.putLong(key, (Long) value);
		}
		else if (value instanceof String)
		{
			editor.putString(key, (String) value);
		}
		else
		{
			throw new IllegalArgumentException(value + " can't be inserted into SharedPreferences");
		}
		editor.commit();
	}

}
